package utils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FileUploadParam {
	private String path;
	private Map<String,List<String>> formParams;
	private Map<String,List<String>> fileParams;

	public FileUploadParam(){
		formParams = new HashMap<String,List<String>>();
		fileParams = new HashMap<String,List<String>>();
		path = null;
	}
	
	public void setPath(String path){
		this.path = path;
	}
			
	public void putFormParams(String key,String value){
		List<String> list = formParams.get(key);
		if(list==null){
			list = new ArrayList<String>();
		}
		list.add(value);
		formParams.put(key, list);
	}
	public String getParameter(String key){
		List<String > list = formParams.get(key);
		if(list == null || list.size() == 0){
			return null;
		}
		return list.get(0);
	}
	public String[] getParameterValues(String key){
		List<String > list = formParams.get(key);
		if(list == null || list.size() == 0){
			return null;
		}
		return list.toArray(new String[list.size()]);
	}
	
	public void putFileParams(String key,String value){
		List<String> list = fileParams.get(key);
		if(list==null){
			list = new ArrayList<String>();
		}
		list.add(value);
		fileParams.put(key, list);
	}
	public String getFileName(String key){
		List<String > list = fileParams.get(key);
		if(list == null || list.size() == 0){
			return null;
		}
		return list.get(0);
	}
	public String[] getFileNames(String key){
		List<String > list = fileParams.get(key);
		if(list == null || list.size() == 0){
			return null;
		}
		return list.toArray(new String[list.size()]);
	}
	
	public String getFilePath(String key){
		String fileName = getFileName(key);
		if(path == null || fileName == null)
			return null;
		return path + File.separator + fileName;
	}
	public String[] getFilePaths(String key){
		String[] fileNames = getFileNames(key);
		if(path == null || fileNames == null)
			return null;
		String[] paths = new String[fileNames.length];
		for(int i=0;i<paths.length;i++){
			paths[i] = path + File.separator + fileNames[i]; 
		}
		return paths;		
	}	
}